package com.liuzihao.cloudLzhConsumer.controller;

import com.liuzihao.cloudLzhConsumer.service.PaymentService;
import com.liuzihao.cloudLzhPayment.pojo.CommentResult;
import com.liuzihao.cloudLzhPayment.pojo.Payment;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author: Liuzihao
 * @Description:
 * @Date Created in 2022-01-25 21:29
 * @Modified By:
 */
@RestController
public class ConsumerController {
    @Resource
    PaymentService paymentService;

    @GetMapping("/consumer/payment/hystrix/ok/{id}")
    String ok(@PathVariable("id") Long id){
        return paymentService.paymentInfo_OK(id);
    }

    @GetMapping("/consumer/payment/hystrix/timeout/{id}")
    @HystrixCommand(fallbackMethod = "paymentTimeOutFallbackMethod",commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "3000")
    })
    String timeout(@PathVariable("id") Long id){
        return paymentService.paymentInfo_TimeOut(id);
    }

    //兜底方法
    String paymentTimeOutFallbackMethod(@PathVariable("id") Long id){
        return "我是消费者80，对付支付系统繁忙请10秒钟后再试或者自己运行出错请检查自己,(┬＿┬)";
    }
}
